<?php

namespace app\admin\controller;

use app\admin\model\NoticeList;
use app\admin\model\UserList;
use app\admin\model\UserNotice;
use app\admin\service\NoticeService;
use think\facade\Request;

class Notice extends Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    public function index()
    {
        if (Request::isAjax()) {
            return $this->getJson(UserNotice::getList());
        }
        return $this->fetch();
    }

    public function edit($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(NoticeService::goEdit());
        }
        $userList = UserList::getAll();
        array_unshift($userList, ['id' => 0, 'name' => '全体人员']);
        $this->assign('userList', $userList);
        return $this->fetch('', ['data' => UserNotice::find($id)]);
    }

    public function goRemove($id)
    {
        return $this->getJson(NoticeService::goRemove($id));
    }

    public function bulletin()
    {
        if (Request::isAjax()) {
            return $this->getJson(NoticeList::getList());
        }
        return $this->fetch();
    }

    public function editBulletin($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(NoticeService::goEditBulletin());
        }
        return $this->fetch('', ['data' => NoticeList::find($id)]);
    }

    public function goRemoveBulletin($id)
    {
        return $this->getJson(NoticeService::goRemoveBulletin($id));
    }

    public function goStatusBulletin($id)
    {
        return $this->getJson(NoticeService::goStatusBulletin());
    }
}